<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module Psych - psych: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#module-Psych-label-Overview">Overview</a>
    <li><a href="#module-Psych-label-I+NEED+TO+PARSE+OR+EMIT+YAML+RIGHT+NOW-21">I NEED TO PARSE OR EMIT YAML RIGHT NOW!</a>
    <li><a href="#module-Psych-label-YAML+Parsing">YAML Parsing</a>
    <li><a href="#module-Psych-label-YAML+Emitting">YAML Emitting</a>
    <li><a href="#module-Psych-label-High-level+API">High-level API</a>
    <li><a href="#module-Psych-label-Parsing">Parsing</a>
    <li><a href="#module-Psych-label-Reading+from+a+string">Reading from a string</a>
    <li><a href="#module-Psych-label-Reading+from+a+file">Reading from a file</a>
    <li><a href="#module-Psych-label-Exception+handling">Exception handling</a>
    <li><a href="#module-Psych-label-Emitting">Emitting</a>
    <li><a href="#module-Psych-label-Writing+to+a+string">Writing to a string</a>
    <li><a href="#module-Psych-label-Writing+to+a+file">Writing to a file</a>
    <li><a href="#module-Psych-label-Mid-level+API">Mid-level API</a>
    <li><a href="#module-Psych-label-Parsing">Parsing</a>
    <li><a href="#module-Psych-label-Reading+from+a+string">Reading from a string</a>
    <li><a href="#module-Psych-label-Reading+from+a+file">Reading from a file</a>
    <li><a href="#module-Psych-label-Exception+handling">Exception handling</a>
    <li><a href="#module-Psych-label-Emitting">Emitting</a>
    <li><a href="#module-Psych-label-Writing+to+a+string">Writing to a string</a>
    <li><a href="#module-Psych-label-Writing+to+a+file">Writing to a file</a>
    <li><a href="#module-Psych-label-Low-level+API">Low-level API</a>
    <li><a href="#module-Psych-label-Parsing">Parsing</a>
    <li><a href="#module-Psych-label-Reading+to+Psych-3A-3ANodes-3A-3AStream+structure">Reading to Psych::Nodes::Stream structure</a>
    <li><a href="#module-Psych-label-Receiving+an+events+stream">Receiving an events stream</a>
    <li><a href="#module-Psych-label-Emitting">Emitting</a>
    <li><a href="#module-Psych-label-Writing+to+a+Ruby+structure">Writing to a Ruby structure</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-dump">::dump</a>
    <li ><a href="#method-c-dump_stream">::dump_stream</a>
    <li ><a href="#method-c-libyaml_version">::libyaml_version</a>
    <li ><a href="#method-c-load">::load</a>
    <li ><a href="#method-c-load_file">::load_file</a>
    <li ><a href="#method-c-load_stream">::load_stream</a>
    <li ><a href="#method-c-parse">::parse</a>
    <li ><a href="#method-c-parse_file">::parse_file</a>
    <li ><a href="#method-c-parse_stream">::parse_stream</a>
    <li ><a href="#method-c-parser">::parser</a>
    <li ><a href="#method-c-safe_dump">::safe_dump</a>
    <li ><a href="#method-c-safe_load">::safe_load</a>
    <li ><a href="#method-c-safe_load_file">::safe_load_file</a>
    <li ><a href="#method-c-to_json">::to_json</a>
    <li ><a href="#method-c-unsafe_load">::unsafe_load</a>
    <li ><a href="#method-c-unsafe_load_file">::unsafe_load_file</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-Psych">
    <h1 id="module-Psych" class="module">
      module Psych
    </h1>

    <section class="description">
    
<h1 id="module-Psych-label-Overview">Overview<span><a href="#module-Psych-label-Overview">&para;</a> <a href="#top">&uarr;</a></span></h1>

<p><a href="Psych.html"><code>Psych</code></a> is a YAML parser and emitter. <a href="Psych.html"><code>Psych</code></a> leverages libyaml [Home page: <a href="https://pyyaml.org/wiki/LibYAML">pyyaml.org/wiki/LibYAML</a>] or [git repo: <a href="https://github.com/yaml/libyaml">github.com/yaml/libyaml</a>] for its YAML parsing and emitting capabilities. In addition to wrapping libyaml, <a href="Psych.html"><code>Psych</code></a> also knows how to serialize and de-serialize most Ruby objects to and from the YAML format.</p>

<h1 id="module-Psych-label-I+NEED+TO+PARSE+OR+EMIT+YAML+RIGHT+NOW-21">I NEED TO PARSE OR EMIT YAML RIGHT NOW!<span><a href="#module-Psych-label-I+NEED+TO+PARSE+OR+EMIT+YAML+RIGHT+NOW-21">&para;</a> <a href="#top">&uarr;</a></span></h1>

<pre class="ruby"><span class="ruby-comment"># Parse some YAML</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&quot;--- foo&quot;</span>) <span class="ruby-comment"># =&gt; &quot;foo&quot;</span>

<span class="ruby-comment"># Emit some YAML</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-string">&quot;foo&quot;</span>)     <span class="ruby-comment"># =&gt; &quot;--- foo\n...\n&quot;</span>
{ <span class="ruby-value">:a</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;b&#39;</span>}.<span class="ruby-identifier">to_yaml</span>  <span class="ruby-comment"># =&gt; &quot;---\n:a: b\n&quot;</span>
</pre>

<p>Got more time on your hands?  Keep on reading!</p>

<h2 id="module-Psych-label-YAML+Parsing">YAML Parsing<span><a href="#module-Psych-label-YAML+Parsing">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p><a href="Psych.html"><code>Psych</code></a> provides a range of interfaces for parsing a YAML document ranging from low level to high level, depending on your parsing needs.  At the lowest level, is an event based parser.  Mid level is access to the raw YAML AST, and at the highest level is the ability to unmarshal YAML to Ruby objects.</p>

<h2 id="module-Psych-label-YAML+Emitting">YAML Emitting<span><a href="#module-Psych-label-YAML+Emitting">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p><a href="Psych.html"><code>Psych</code></a> provides a range of interfaces ranging from low to high level for producing YAML documents.  Very similar to the YAML parsing interfaces, <a href="Psych.html"><code>Psych</code></a> provides at the lowest level, an event based system, mid-level is building a YAML AST, and the highest level is converting a Ruby object straight to a YAML document.</p>

<h2 id="module-Psych-label-High-level+API">High-level API<span><a href="#module-Psych-label-High-level+API">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h3 id="module-Psych-label-Parsing">Parsing<span><a href="#module-Psych-label-Parsing">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>The high level YAML parser provided by <a href="Psych.html"><code>Psych</code></a> simply takes YAML as input and returns a Ruby data structure.  For information on using the high level parser see <a href="Psych.html#method-c-load"><code>Psych.load</code></a></p>

<h4 id="module-Psych-label-Reading+from+a+string">Reading from a string<span><a href="#module-Psych-label-Reading+from+a+string">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_load</span>(<span class="ruby-string">&quot;--- a&quot;</span>)             <span class="ruby-comment"># =&gt; &#39;a&#39;</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_load</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>)   <span class="ruby-comment"># =&gt; [&#39;a&#39;, &#39;b&#39;]</span>
<span class="ruby-comment"># From a trusted string:</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&quot;--- !ruby/range\nbegin: 0\nend: 42\nexcl: false\n&quot;</span>) <span class="ruby-comment"># =&gt; 0..42</span>
</pre>

<h4 id="module-Psych-label-Reading+from+a+file">Reading from a file<span><a href="#module-Psych-label-Reading+from+a+file">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_load_file</span>(<span class="ruby-string">&quot;data.yml&quot;</span>, <span class="ruby-value">permitted_classes:</span> [<span class="ruby-constant">Date</span>])
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load_file</span>(<span class="ruby-string">&quot;trusted_database.yml&quot;</span>)
</pre>

<h4 id="module-Psych-label-Exception+handling"><a href="Psych/Exception.html"><code>Exception</code></a> handling<span><a href="#module-Psych-label-Exception+handling">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-keyword">begin</span>
  <span class="ruby-comment"># The second argument changes only the exception contents</span>
  <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;--- `&quot;</span>, <span class="ruby-string">&quot;file.txt&quot;</span>)
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">SyntaxError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">ex</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">file</span>    <span class="ruby-comment"># =&gt; &#39;file.txt&#39;</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span> <span class="ruby-comment"># =&gt; &quot;(file.txt): found character that cannot start any token&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<h3 id="module-Psych-label-Emitting">Emitting<span><a href="#module-Psych-label-Emitting">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>The high level emitter has the easiest interface.  <a href="Psych.html"><code>Psych</code></a> simply takes a Ruby data structure and converts it to a YAML document.  See <a href="Psych.html#method-c-dump"><code>Psych.dump</code></a> for more information on dumping a Ruby data structure.</p>

<h4 id="module-Psych-label-Writing+to+a+string">Writing to a string<span><a href="#module-Psych-label-Writing+to+a+string">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-comment"># Dump an array, get back a YAML string</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>])  <span class="ruby-comment"># =&gt; &quot;---\n- a\n- b\n&quot;</span>

<span class="ruby-comment"># Dump an array to an IO object</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>], <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>)  <span class="ruby-comment"># =&gt; #&lt;StringIO:0x000001009d0890&gt;</span>

<span class="ruby-comment"># Dump an array with indentation set</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, [<span class="ruby-string">&#39;b&#39;</span>]], <span class="ruby-value">:indentation</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">3</span>) <span class="ruby-comment"># =&gt; &quot;---\n- a\n-  - b\n&quot;</span>

<span class="ruby-comment"># Dump an array to an IO with indentation set</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, [<span class="ruby-string">&#39;b&#39;</span>]], <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>, <span class="ruby-value">:indentation</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">3</span>)
</pre>

<h4 id="module-Psych-label-Writing+to+a+file">Writing to a file<span><a href="#module-Psych-label-Writing+to+a+file">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Currently there is no direct API for dumping Ruby structure to file:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;database.yml&#39;</span>, <span class="ruby-string">&#39;w&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">file</span>.<span class="ruby-identifier">write</span>(<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>]))
<span class="ruby-keyword">end</span>
</pre>

<h2 id="module-Psych-label-Mid-level+API">Mid-level API<span><a href="#module-Psych-label-Mid-level+API">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h3 id="module-Psych-label-Parsing">Parsing<span><a href="#module-Psych-label-Parsing">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p><a href="Psych.html"><code>Psych</code></a> provides access to an AST produced from parsing a YAML document.  This tree is built using the <a href="Psych/Parser.html"><code>Psych::Parser</code></a> and <a href="Psych/TreeBuilder.html"><code>Psych::TreeBuilder</code></a>.  The AST can be examined and manipulated freely.  Please see <a href="Psych.html#method-c-parse_stream"><code>Psych::parse_stream</code></a>, <a href="Psych/Nodes.html"><code>Psych::Nodes</code></a>, and <a href="Psych/Nodes/Node.html"><code>Psych::Nodes::Node</code></a> for more information on dealing with YAML syntax trees.</p>

<h4 id="module-Psych-label-Reading+from+a+string">Reading from a string<span><a href="#module-Psych-label-Reading+from+a+string">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-comment"># Returns Psych::Nodes::Stream</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse_stream</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>)

<span class="ruby-comment"># Returns Psych::Nodes::Document</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>)
</pre>

<h4 id="module-Psych-label-Reading+from+a+file">Reading from a file<span><a href="#module-Psych-label-Reading+from+a+file">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-comment"># Returns Psych::Nodes::Stream</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse_stream</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-string">&#39;database.yml&#39;</span>))

<span class="ruby-comment"># Returns Psych::Nodes::Document</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse_file</span>(<span class="ruby-string">&#39;database.yml&#39;</span>)
</pre>

<h4 id="module-Psych-label-Exception+handling"><a href="Psych/Exception.html"><code>Exception</code></a> handling<span><a href="#module-Psych-label-Exception+handling">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-keyword">begin</span>
  <span class="ruby-comment"># The second argument changes only the exception contents</span>
  <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;--- `&quot;</span>, <span class="ruby-string">&quot;file.txt&quot;</span>)
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">SyntaxError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">ex</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">file</span>    <span class="ruby-comment"># =&gt; &#39;file.txt&#39;</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span> <span class="ruby-comment"># =&gt; &quot;(file.txt): found character that cannot start any token&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<h3 id="module-Psych-label-Emitting">Emitting<span><a href="#module-Psych-label-Emitting">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>At the mid level is building an AST.  This AST is exactly the same as the AST used when parsing a YAML document.  Users can build an AST by hand and the AST knows how to emit itself as a YAML document.  See <a href="Psych/Nodes.html"><code>Psych::Nodes</code></a>, <a href="Psych/Nodes/Node.html"><code>Psych::Nodes::Node</code></a>, and <a href="Psych/TreeBuilder.html"><code>Psych::TreeBuilder</code></a> for more information on building a YAML AST.</p>

<h4 id="module-Psych-label-Writing+to+a+string">Writing to a string<span><a href="#module-Psych-label-Writing+to+a+string">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-comment"># We need Psych::Nodes::Stream (not Psych::Nodes::Document)</span>
<span class="ruby-identifier">stream</span> = <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse_stream</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>)

<span class="ruby-identifier">stream</span>.<span class="ruby-identifier">to_yaml</span> <span class="ruby-comment"># =&gt; &quot;---\n- a\n- b\n&quot;</span>
</pre>

<h4 id="module-Psych-label-Writing+to+a+file">Writing to a file<span><a href="#module-Psych-label-Writing+to+a+file">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-comment"># We need Psych::Nodes::Stream (not Psych::Nodes::Document)</span>
<span class="ruby-identifier">stream</span> = <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse_stream</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-string">&#39;database.yml&#39;</span>))

<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;database.yml&#39;</span>, <span class="ruby-string">&#39;w&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">file</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">stream</span>.<span class="ruby-identifier">to_yaml</span>)
<span class="ruby-keyword">end</span>
</pre>

<h2 id="module-Psych-label-Low-level+API">Low-level API<span><a href="#module-Psych-label-Low-level+API">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h3 id="module-Psych-label-Parsing">Parsing<span><a href="#module-Psych-label-Parsing">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>The lowest level parser should be used when the YAML input is already known, and the developer does not want to pay the price of building an AST or automatic detection and conversion to Ruby objects.  See <a href="Psych/Parser.html"><code>Psych::Parser</code></a> for more information on using the event based parser.</p>

<h4 id="module-Psych-label-Reading+to+Psych-3A-3ANodes-3A-3AStream+structure">Reading to <a href="Psych/Nodes/Stream.html"><code>Psych::Nodes::Stream</code></a> structure<span><a href="#module-Psych-label-Reading+to+Psych-3A-3ANodes-3A-3AStream+structure">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">parser</span> = <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">TreeBuilder</span>.<span class="ruby-identifier">new</span>) <span class="ruby-comment"># =&gt; #&lt;Psych::Parser&gt;</span>
<span class="ruby-identifier">parser</span> = <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parser</span>                       <span class="ruby-comment"># it&#39;s an alias for the above</span>

<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>)             <span class="ruby-comment"># =&gt; #&lt;Psych::Parser&gt;</span>
<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">handler</span>                              <span class="ruby-comment"># =&gt; #&lt;Psych::TreeBuilder&gt;</span>
<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">handler</span>.<span class="ruby-identifier">root</span>                         <span class="ruby-comment"># =&gt; #&lt;Psych::Nodes::Stream&gt;</span>
</pre>

<h4 id="module-Psych-label-Receiving+an+events+stream">Receiving an events stream<span><a href="#module-Psych-label-Receiving+an+events+stream">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">recorder</span> = <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Handlers</span><span class="ruby-operator">::</span><span class="ruby-constant">Recorder</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">parser</span> = <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">recorder</span>)

<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>)
<span class="ruby-identifier">recorder</span>.<span class="ruby-identifier">events</span> <span class="ruby-comment"># =&gt; [list of [event, args] lists]</span>
                <span class="ruby-comment"># event is one of: Psych::Handler::EVENTS</span>
                <span class="ruby-comment"># args are the arguments passed to the event</span>
</pre>

<h3 id="module-Psych-label-Emitting">Emitting<span><a href="#module-Psych-label-Emitting">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>The lowest level emitter is an event based system.  Events are sent to a <a href="Psych/Emitter.html"><code>Psych::Emitter</code></a> object.  That object knows how to convert the events to a YAML document.  This interface should be used when document format is known in advance or speed is a concern.  See <a href="Psych/Emitter.html"><code>Psych::Emitter</code></a> for more information.</p>

<h4 id="module-Psych-label-Writing+to+a+Ruby+structure">Writing to a Ruby structure<span><a href="#module-Psych-label-Writing+to+a+Ruby+structure">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;--- a&quot;</span>)       <span class="ruby-comment"># =&gt; #&lt;Psych::Parser&gt;</span>

<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">handler</span>.<span class="ruby-identifier">first</span>              <span class="ruby-comment"># =&gt; #&lt;Psych::Nodes::Stream&gt;</span>
<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">handler</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">to_ruby</span>      <span class="ruby-comment"># =&gt; [&quot;a&quot;]</span>

<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">handler</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">first</span>         <span class="ruby-comment"># =&gt; #&lt;Psych::Nodes::Document&gt;</span>
<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">handler</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">to_ruby</span> <span class="ruby-comment"># =&gt; &quot;a&quot;</span>

<span class="ruby-comment"># You can instantiate an Emitter manually</span>
<span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Visitors</span><span class="ruby-operator">::</span><span class="ruby-constant">ToRuby</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">accept</span>(<span class="ruby-identifier">parser</span>.<span class="ruby-identifier">handler</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">first</span>)
<span class="ruby-comment"># =&gt; &quot;a&quot;</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="DEFAULT_SNAKEYAML_VERSION">DEFAULT_SNAKEYAML_VERSION
          <dd>
          <dt id="LIBYAML_VERSION">LIBYAML_VERSION
          <dd><p>The version of libyaml <a href="Psych.html"><code>Psych</code></a> is using</p>
          <dt id="VERSION">VERSION
          <dd><p>The version of <a href="Psych.html"><code>Psych</code></a> you are using</p>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-dump" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dump(o)               &rarr; string of yaml
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          dump(o, options)      &rarr; string of yaml
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          dump(o, io)           &rarr; io object passed in
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          dump(o, io, options)  &rarr; io object passed in
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Dump Ruby object <code>o</code> to a YAML string.  Optional <code>options</code> may be passed in to control the output format.  If an IO object is passed in, the YAML will be dumped to that IO object.</p>

<p>Currently supported options are:</p>
<dl class="rdoc-list label-list"><dt><code>:indentation</code>
<dd>
<p>Number of space characters used to indent. Acceptable value should be in <code>0..9</code> range, otherwise option is ignored.</p>

<p>Default: <code>2</code>.</p>
</dd><dt><code>:line_width</code>
<dd>
<p>Max character to wrap line at.</p>

<p>Default: <code>0</code> (meaning “wrap at 81”).</p>
</dd><dt><code>:canonical</code>
<dd>
<p>Write “canonical” YAML form (very verbose, yet strictly formal).</p>

<p>Default: <code>false</code>.</p>
</dd><dt><code>:header</code>
<dd>
<p>Write <code>%YAML [version]</code> at the beginning of document.</p>

<p>Default: <code>false</code>.</p>
</dd></dl>

<p>Example:</p>

<pre class="ruby"><span class="ruby-comment"># Dump an array, get back a YAML string</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>])  <span class="ruby-comment"># =&gt; &quot;---\n- a\n- b\n&quot;</span>

<span class="ruby-comment"># Dump an array to an IO object</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>], <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>)  <span class="ruby-comment"># =&gt; #&lt;StringIO:0x000001009d0890&gt;</span>

<span class="ruby-comment"># Dump an array with indentation set</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, [<span class="ruby-string">&#39;b&#39;</span>]], <span class="ruby-value">indentation:</span> <span class="ruby-value">3</span>) <span class="ruby-comment"># =&gt; &quot;---\n- a\n-  - b\n&quot;</span>

<span class="ruby-comment"># Dump an array to an IO with indentation set</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span>([<span class="ruby-string">&#39;a&#39;</span>, [<span class="ruby-string">&#39;b&#39;</span>]], <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>, <span class="ruby-value">indentation:</span> <span class="ruby-value">3</span>)
</pre>

                              <div class="method-source-code" id="dump-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 505</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">dump</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">io</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {}
  <span class="ruby-keyword">if</span> <span class="ruby-constant">Hash</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">io</span>
    <span class="ruby-identifier">options</span> = <span class="ruby-identifier">io</span>
    <span class="ruby-identifier">io</span>      = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">visitor</span> = <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Visitors</span><span class="ruby-operator">::</span><span class="ruby-constant">YAMLTree</span>.<span class="ruby-identifier">create</span> <span class="ruby-identifier">options</span>
  <span class="ruby-identifier">visitor</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">o</span>
  <span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">yaml</span> <span class="ruby-identifier">io</span>, <span class="ruby-identifier">options</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-dump_stream" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">dump_stream</span><span
                                class="method-args">(*objects)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Dump a list of objects as separate documents to a document stream.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump_stream</span>(<span class="ruby-string">&quot;foo\n  &quot;</span>, {}) <span class="ruby-comment"># =&gt; &quot;--- ! \&quot;foo\\n  \&quot;\n--- {}\n&quot;</span>
</pre>

                              <div class="method-source-code" id="dump_stream-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 595</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">dump_stream</span> <span class="ruby-operator">*</span><span class="ruby-identifier">objects</span>
  <span class="ruby-identifier">visitor</span> = <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Visitors</span><span class="ruby-operator">::</span><span class="ruby-constant">YAMLTree</span>.<span class="ruby-identifier">create</span>({})
  <span class="ruby-identifier">objects</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">visitor</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">o</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">yaml</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-libyaml_version" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          libyaml_version
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the version of libyaml being used</p>

                              <div class="method-source-code" id="libyaml_version-source">
            <pre>static VALUE libyaml_version(VALUE module)
{
    int major, minor, patch;
    VALUE list[3];

    yaml_get_version(&amp;major, &amp;minor, &amp;patch);

    list[0] = INT2NUM(major);
    list[1] = INT2NUM(minor);
    list[2] = INT2NUM(patch);

    return rb_ary_new4((long)3, list);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-load" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">load</span><span
                                class="method-args">(yaml, permitted_classes: [Symbol], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false, strict_integer: false)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Load <code>yaml</code> in to a Ruby data structure.  If multiple documents are provided, the object contained in the first document will be returned. <code>filename</code> will be used in the exception message if any exception is raised while parsing.  If <code>yaml</code> is empty, it returns the specified <code>fallback</code> return value, which defaults to <code>false</code>.</p>

<p>Raises a <a href="Psych/SyntaxError.html"><code>Psych::SyntaxError</code></a> when a YAML syntax error is detected.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&quot;--- a&quot;</span>)             <span class="ruby-comment"># =&gt; &#39;a&#39;</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>)   <span class="ruby-comment"># =&gt; [&#39;a&#39;, &#39;b&#39;]</span>

<span class="ruby-keyword">begin</span>
  <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&quot;--- `&quot;</span>, <span class="ruby-value">filename:</span> <span class="ruby-string">&quot;file.txt&quot;</span>)
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">SyntaxError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">ex</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">file</span>    <span class="ruby-comment"># =&gt; &#39;file.txt&#39;</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span> <span class="ruby-comment"># =&gt; &quot;(file.txt): found character that cannot start any token&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<p>When the optional <code>symbolize_names</code> keyword argument is set to a true value, returns symbols for keys in Hash objects (default: strings).</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&quot;---\n foo: bar&quot;</span>)                         <span class="ruby-comment"># =&gt; {&quot;foo&quot;=&gt;&quot;bar&quot;}</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load</span>(<span class="ruby-string">&quot;---\n foo: bar&quot;</span>, <span class="ruby-value">symbolize_names:</span> <span class="ruby-keyword">true</span>)  <span class="ruby-comment"># =&gt; {:foo=&gt;&quot;bar&quot;}</span>
</pre>

<p>Raises a TypeError when ‘yaml` parameter is NilClass.  This method is similar to `safe_load` except that `Symbol` objects are allowed by default.</p>

                              <div class="method-source-code" id="load-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 368</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">load</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-value">permitted_classes:</span> [<span class="ruby-constant">Symbol</span>], <span class="ruby-value">permitted_symbols:</span> [], <span class="ruby-value">aliases:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">filename:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">fallback:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">symbolize_names:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">freeze:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">strict_integer:</span> <span class="ruby-keyword">false</span>
  <span class="ruby-identifier">safe_load</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-value">permitted_classes:</span> <span class="ruby-identifier">permitted_classes</span>,
                  <span class="ruby-value">permitted_symbols:</span> <span class="ruby-identifier">permitted_symbols</span>,
                  <span class="ruby-value">aliases:</span> <span class="ruby-identifier">aliases</span>,
                  <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>,
                  <span class="ruby-value">fallback:</span> <span class="ruby-identifier">fallback</span>,
                  <span class="ruby-value">symbolize_names:</span> <span class="ruby-identifier">symbolize_names</span>,
                  <span class="ruby-value">freeze:</span> <span class="ruby-identifier">freeze</span>,
                  <span class="ruby-value">strict_integer:</span> <span class="ruby-identifier">strict_integer</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-load_file" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">load_file</span><span
                                class="method-args">(filename, **kwargs)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Loads the document contained in <code>filename</code>.  Returns the yaml contained in <code>filename</code> as a Ruby object, or if the file is empty, it returns the specified <code>fallback</code> return value, which defaults to <code>false</code>. See load for options.</p>

                              <div class="method-source-code" id="load_file-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 669</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">load_file</span> <span class="ruby-identifier">filename</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>
  <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-string">&#39;r:bom|utf-8&#39;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">load</span> <span class="ruby-identifier">f</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-load_stream" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">load_stream</span><span
                                class="method-args">(yaml, filename: nil, fallback: [], **kwargs) { |to_ruby(**kwargs)| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Load multiple documents given in <code>yaml</code>.  Returns the parsed documents as a list.  If a block is given, each document will be converted to Ruby and passed to the block during parsing</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load_stream</span>(<span class="ruby-string">&quot;--- foo\n...\n--- bar\n...&quot;</span>) <span class="ruby-comment"># =&gt; [&#39;foo&#39;, &#39;bar&#39;]</span>

<span class="ruby-identifier">list</span> = []
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">load_stream</span>(<span class="ruby-string">&quot;--- foo\n...\n--- bar\n...&quot;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ruby</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">list</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">ruby</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">list</span> <span class="ruby-comment"># =&gt; [&#39;foo&#39;, &#39;bar&#39;]</span>
</pre>

                              <div class="method-source-code" id="load_stream-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 626</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">load_stream</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">fallback:</span> [], <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>
  <span class="ruby-identifier">result</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
             <span class="ruby-identifier">parse_stream</span>(<span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
               <span class="ruby-keyword">yield</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">to_ruby</span>(<span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>)
             <span class="ruby-keyword">end</span>
           <span class="ruby-keyword">else</span>
             <span class="ruby-identifier">parse_stream</span>(<span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>).<span class="ruby-identifier">children</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">to_ruby</span>(<span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>) }
           <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">fallback</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">empty?</span>
  <span class="ruby-identifier">result</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-parse" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">parse</span><span
                                class="method-args">(yaml, filename: nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Parse a YAML string in <code>yaml</code>.  Returns the <a href="Psych/Nodes/Document.html"><code>Psych::Nodes::Document</code></a>. <code>filename</code> is used in the exception message if a <a href="Psych/SyntaxError.html"><code>Psych::SyntaxError</code></a> is raised.</p>

<p>Raises a <a href="Psych/SyntaxError.html"><code>Psych::SyntaxError</code></a> when a YAML syntax error is detected.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>) <span class="ruby-comment"># =&gt; #&lt;Psych::Nodes::Document:0x00&gt;</span>

<span class="ruby-keyword">begin</span>
  <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;--- `&quot;</span>, <span class="ruby-value">filename:</span> <span class="ruby-string">&quot;file.txt&quot;</span>)
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">SyntaxError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">ex</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">file</span>    <span class="ruby-comment"># =&gt; &#39;file.txt&#39;</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span> <span class="ruby-comment"># =&gt; &quot;(file.txt): found character that cannot start any token&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<p>See <a href="Psych/Nodes.html"><code>Psych::Nodes</code></a> for more information about YAML AST.</p>

                              <div class="method-source-code" id="parse-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 398</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">parse</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">parse_stream</span>(<span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">node</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-parse_file" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">parse_file</span><span
                                class="method-args">(filename, fallback: false)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Parse a file at <code>filename</code>. Returns the <a href="Psych/Nodes/Document.html"><code>Psych::Nodes::Document</code></a>.</p>

<p>Raises a <a href="Psych/SyntaxError.html"><code>Psych::SyntaxError</code></a> when a YAML syntax error is detected.</p>

                              <div class="method-source-code" id="parse_file-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 410</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">parse_file</span> <span class="ruby-identifier">filename</span>, <span class="ruby-value">fallback:</span> <span class="ruby-keyword">false</span>
  <span class="ruby-identifier">result</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span> <span class="ruby-identifier">filename</span>, <span class="ruby-string">&#39;r:bom|utf-8&#39;</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">parse</span> <span class="ruby-identifier">f</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">result</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">fallback</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-parse_stream" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">parse_stream</span><span
                                class="method-args">(yaml, filename: nil, &amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Parse a YAML string in <code>yaml</code>.  Returns the <a href="Psych/Nodes/Stream.html"><code>Psych::Nodes::Stream</code></a>. This method can handle multiple YAML documents contained in <code>yaml</code>. <code>filename</code> is used in the exception message if a <a href="Psych/SyntaxError.html"><code>Psych::SyntaxError</code></a> is raised.</p>

<p>If a block is given, a <a href="Psych/Nodes/Document.html"><code>Psych::Nodes::Document</code></a> node will be yielded to the block as it’s being parsed.</p>

<p>Raises a <a href="Psych/SyntaxError.html"><code>Psych::SyntaxError</code></a> when a YAML syntax error is detected.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse_stream</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>) <span class="ruby-comment"># =&gt; #&lt;Psych::Nodes::Stream:0x00&gt;</span>

<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse_stream</span>(<span class="ruby-string">&quot;--- a\n--- b&quot;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">node</span> <span class="ruby-comment"># =&gt; #&lt;Psych::Nodes::Document:0x00&gt;</span>
<span class="ruby-keyword">end</span>

<span class="ruby-keyword">begin</span>
  <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">parse_stream</span>(<span class="ruby-string">&quot;--- `&quot;</span>, <span class="ruby-value">filename:</span> <span class="ruby-string">&quot;file.txt&quot;</span>)
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">SyntaxError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">ex</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">file</span>    <span class="ruby-comment"># =&gt; &#39;file.txt&#39;</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span> <span class="ruby-comment"># =&gt; &quot;(file.txt): found character that cannot start any token&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Raises a TypeError when NilClass is passed.</p>

<p>See <a href="Psych/Nodes.html"><code>Psych::Nodes</code></a> for more information about YAML AST.</p>

                              <div class="method-source-code" id="parse_stream-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 452</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">parse_stream</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
    <span class="ruby-identifier">parser</span> = <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Handlers</span><span class="ruby-operator">::</span><span class="ruby-constant">DocumentStream</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>))
    <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">parse</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-identifier">filename</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">parser</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">parser</span>
    <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">parse</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-identifier">filename</span>
    <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">handler</span>.<span class="ruby-identifier">root</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-parser" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">parser</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a default parser</p>

                              <div class="method-source-code" id="parser-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 419</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">parser</span>
  <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">TreeBuilder</span>.<span class="ruby-identifier">new</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-safe_dump" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          safe_dump(o)               &rarr; string of yaml
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          safe_dump(o, options)      &rarr; string of yaml
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          safe_dump(o, io)           &rarr; io object passed in
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          safe_dump(o, io, options)  &rarr; io object passed in
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Safely dump Ruby object <code>o</code> to a YAML string. Optional <code>options</code> may be passed in to control the output format.  If an IO object is passed in, the YAML will be dumped to that IO object. By default, only the following classes are allowed to be serialized:</p>
<ul><li>
<p>TrueClass</p>
</li><li>
<p>FalseClass</p>
</li><li>
<p>NilClass</p>
</li><li>
<p>Integer</p>
</li><li>
<p>Float</p>
</li><li>
<p>String</p>
</li><li>
<p>Array</p>
</li><li>
<p>Hash</p>
</li></ul>

<p>Arbitrary classes can be allowed by adding those classes to the <code>permitted_classes</code> keyword argument.  They are additive.  For example, to allow Date serialization:</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_dump</span>(<span class="ruby-identifier">yaml</span>, <span class="ruby-value">permitted_classes:</span> [<span class="ruby-constant">Date</span>])
</pre>

<p>Now the Date class can be dumped in addition to the classes listed above.</p>

<p>A <a href="Psych/DisallowedClass.html"><code>Psych::DisallowedClass</code></a> exception will be raised if the object contains a class that isn’t in the <code>permitted_classes</code> list.</p>

<p>Currently supported options are:</p>
<dl class="rdoc-list label-list"><dt><code>:indentation</code>
<dd>
<p>Number of space characters used to indent. Acceptable value should be in <code>0..9</code> range, otherwise option is ignored.</p>

<p>Default: <code>2</code>.</p>
</dd><dt><code>:line_width</code>
<dd>
<p>Max character to wrap line at.</p>

<p>Default: <code>0</code> (meaning “wrap at 81”).</p>
</dd><dt><code>:canonical</code>
<dd>
<p>Write “canonical” YAML form (very verbose, yet strictly formal).</p>

<p>Default: <code>false</code>.</p>
</dd><dt><code>:header</code>
<dd>
<p>Write <code>%YAML [version]</code> at the beginning of document.</p>

<p>Default: <code>false</code>.</p>
</dd></dl>

<p>Example:</p>

<pre class="ruby"><span class="ruby-comment"># Dump an array, get back a YAML string</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_dump</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>])  <span class="ruby-comment"># =&gt; &quot;---\n- a\n- b\n&quot;</span>

<span class="ruby-comment"># Dump an array to an IO object</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_dump</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>], <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>)  <span class="ruby-comment"># =&gt; #&lt;StringIO:0x000001009d0890&gt;</span>

<span class="ruby-comment"># Dump an array with indentation set</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_dump</span>([<span class="ruby-string">&#39;a&#39;</span>, [<span class="ruby-string">&#39;b&#39;</span>]], <span class="ruby-value">indentation:</span> <span class="ruby-value">3</span>) <span class="ruby-comment"># =&gt; &quot;---\n- a\n-  - b\n&quot;</span>

<span class="ruby-comment"># Dump an array to an IO with indentation set</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_dump</span>([<span class="ruby-string">&#39;a&#39;</span>, [<span class="ruby-string">&#39;b&#39;</span>]], <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>, <span class="ruby-value">indentation:</span> <span class="ruby-value">3</span>)
</pre>

                              <div class="method-source-code" id="safe_dump-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 578</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">safe_dump</span> <span class="ruby-identifier">o</span>, <span class="ruby-identifier">io</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {}
  <span class="ruby-keyword">if</span> <span class="ruby-constant">Hash</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">io</span>
    <span class="ruby-identifier">options</span> = <span class="ruby-identifier">io</span>
    <span class="ruby-identifier">io</span>      = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">visitor</span> = <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Visitors</span><span class="ruby-operator">::</span><span class="ruby-constant">RestrictedYAMLTree</span>.<span class="ruby-identifier">create</span> <span class="ruby-identifier">options</span>
  <span class="ruby-identifier">visitor</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">o</span>
  <span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">yaml</span> <span class="ruby-identifier">io</span>, <span class="ruby-identifier">options</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-safe_load" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">safe_load</span><span
                                class="method-args">(yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil, fallback: nil, symbolize_names: false, freeze: false, strict_integer: false)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Safely load the yaml string in <code>yaml</code>.  By default, only the following classes are allowed to be deserialized:</p>
<ul><li>
<p>TrueClass</p>
</li><li>
<p>FalseClass</p>
</li><li>
<p>NilClass</p>
</li><li>
<p>Integer</p>
</li><li>
<p>Float</p>
</li><li>
<p>String</p>
</li><li>
<p>Array</p>
</li><li>
<p>Hash</p>
</li></ul>

<p>Recursive data structures are not allowed by default.  Arbitrary classes can be allowed by adding those classes to the <code>permitted_classes</code> keyword argument.  They are additive.  For example, to allow Date deserialization:</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_load</span>(<span class="ruby-identifier">yaml</span>, <span class="ruby-value">permitted_classes:</span> [<span class="ruby-constant">Date</span>])
</pre>

<p>Now the Date class can be loaded in addition to the classes listed above.</p>

<p>Aliases can be explicitly allowed by changing the <code>aliases</code> keyword argument. For example:</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = []
<span class="ruby-identifier">x</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">x</span>
<span class="ruby-identifier">yaml</span> = <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">dump</span> <span class="ruby-identifier">x</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_load</span> <span class="ruby-identifier">yaml</span>               <span class="ruby-comment"># =&gt; raises an exception</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_load</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-value">aliases:</span> <span class="ruby-keyword">true</span> <span class="ruby-comment"># =&gt; loads the aliases</span>
</pre>

<p>A <a href="Psych/DisallowedClass.html"><code>Psych::DisallowedClass</code></a> exception will be raised if the yaml contains a class that isn’t in the <code>permitted_classes</code> list.</p>

<p>A <a href="Psych/AliasesNotEnabled.html"><code>Psych::AliasesNotEnabled</code></a> exception will be raised if the yaml contains aliases but the <code>aliases</code> keyword argument is set to false.</p>

<p><code>filename</code> will be used in the exception message if any exception is raised while parsing.</p>

<p>When the optional <code>symbolize_names</code> keyword argument is set to a true value, returns symbols for keys in Hash objects (default: strings).</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_load</span>(<span class="ruby-string">&quot;---\n foo: bar&quot;</span>)                         <span class="ruby-comment"># =&gt; {&quot;foo&quot;=&gt;&quot;bar&quot;}</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">safe_load</span>(<span class="ruby-string">&quot;---\n foo: bar&quot;</span>, <span class="ruby-value">symbolize_names:</span> <span class="ruby-keyword">true</span>)  <span class="ruby-comment"># =&gt; {:foo=&gt;&quot;bar&quot;}</span>
</pre>

                              <div class="method-source-code" id="safe_load-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 322</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">safe_load</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-value">permitted_classes:</span> [], <span class="ruby-value">permitted_symbols:</span> [], <span class="ruby-value">aliases:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">filename:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">fallback:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">symbolize_names:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">freeze:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">strict_integer:</span> <span class="ruby-keyword">false</span>
  <span class="ruby-identifier">result</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">fallback</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">result</span>

  <span class="ruby-identifier">class_loader</span> = <span class="ruby-constant">ClassLoader</span><span class="ruby-operator">::</span><span class="ruby-constant">Restricted</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">permitted_classes</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:to_s</span>),
                                             <span class="ruby-identifier">permitted_symbols</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:to_s</span>))
  <span class="ruby-identifier">scanner</span>      = <span class="ruby-constant">ScalarScanner</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">class_loader</span>, <span class="ruby-value">strict_integer:</span> <span class="ruby-identifier">strict_integer</span>
  <span class="ruby-identifier">visitor</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">aliases</span>
              <span class="ruby-constant">Visitors</span><span class="ruby-operator">::</span><span class="ruby-constant">ToRuby</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">scanner</span>, <span class="ruby-identifier">class_loader</span>, <span class="ruby-value">symbolize_names:</span> <span class="ruby-identifier">symbolize_names</span>, <span class="ruby-value">freeze:</span> <span class="ruby-identifier">freeze</span>
            <span class="ruby-keyword">else</span>
              <span class="ruby-constant">Visitors</span><span class="ruby-operator">::</span><span class="ruby-constant">NoAliasRuby</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">scanner</span>, <span class="ruby-identifier">class_loader</span>, <span class="ruby-value">symbolize_names:</span> <span class="ruby-identifier">symbolize_names</span>, <span class="ruby-value">freeze:</span> <span class="ruby-identifier">freeze</span>
            <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">result</span> = <span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">accept</span> <span class="ruby-identifier">result</span>
  <span class="ruby-identifier">result</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-safe_load_file" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">safe_load_file</span><span
                                class="method-args">(filename, **kwargs)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Safely loads the document contained in <code>filename</code>.  Returns the yaml contained in <code>filename</code> as a Ruby object, or if the file is empty, it returns the specified <code>fallback</code> return value, which defaults to <code>false</code>. See <a href="Psych.html#method-c-safe_load"><code>safe_load</code></a> for options.</p>

                              <div class="method-source-code" id="safe_load_file-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 658</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">safe_load_file</span> <span class="ruby-identifier">filename</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>
  <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-string">&#39;r:bom|utf-8&#39;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">safe_load</span> <span class="ruby-identifier">f</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-to_json" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">to_json</span><span
                                class="method-args">(object)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Dump Ruby <code>object</code> to a <a href="Psych/JSON.html"><code>JSON</code></a> string.</p>

                              <div class="method-source-code" id="to_json-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 605</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">to_json</span> <span class="ruby-identifier">object</span>
  <span class="ruby-identifier">visitor</span> = <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">Visitors</span><span class="ruby-operator">::</span><span class="ruby-constant">JSONTree</span>.<span class="ruby-identifier">create</span>
  <span class="ruby-identifier">visitor</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">object</span>
  <span class="ruby-identifier">visitor</span>.<span class="ruby-identifier">tree</span>.<span class="ruby-identifier">yaml</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-unsafe_load" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">unsafe_load</span><span
                                class="method-args">(yaml, filename: nil, fallback: false, symbolize_names: false, freeze: false, strict_integer: false)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Load <code>yaml</code> in to a Ruby data structure.  If multiple documents are provided, the object contained in the first document will be returned. <code>filename</code> will be used in the exception message if any exception is raised while parsing.  If <code>yaml</code> is empty, it returns the specified <code>fallback</code> return value, which defaults to <code>false</code>.</p>

<p>Raises a <a href="Psych/SyntaxError.html"><code>Psych::SyntaxError</code></a> when a YAML syntax error is detected.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">unsafe_load</span>(<span class="ruby-string">&quot;--- a&quot;</span>)             <span class="ruby-comment"># =&gt; &#39;a&#39;</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">unsafe_load</span>(<span class="ruby-string">&quot;---\n - a\n - b&quot;</span>)   <span class="ruby-comment"># =&gt; [&#39;a&#39;, &#39;b&#39;]</span>

<span class="ruby-keyword">begin</span>
  <span class="ruby-constant">Psych</span>.<span class="ruby-identifier">unsafe_load</span>(<span class="ruby-string">&quot;--- `&quot;</span>, <span class="ruby-value">filename:</span> <span class="ruby-string">&quot;file.txt&quot;</span>)
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Psych</span><span class="ruby-operator">::</span><span class="ruby-constant">SyntaxError</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">ex</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">file</span>    <span class="ruby-comment"># =&gt; &#39;file.txt&#39;</span>
  <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span> <span class="ruby-comment"># =&gt; &quot;(file.txt): found character that cannot start any token&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<p>When the optional <code>symbolize_names</code> keyword argument is set to a true value, returns symbols for keys in Hash objects (default: strings).</p>

<pre class="ruby"><span class="ruby-constant">Psych</span>.<span class="ruby-identifier">unsafe_load</span>(<span class="ruby-string">&quot;---\n foo: bar&quot;</span>)                         <span class="ruby-comment"># =&gt; {&quot;foo&quot;=&gt;&quot;bar&quot;}</span>
<span class="ruby-constant">Psych</span>.<span class="ruby-identifier">unsafe_load</span>(<span class="ruby-string">&quot;---\n foo: bar&quot;</span>, <span class="ruby-value">symbolize_names:</span> <span class="ruby-keyword">true</span>)  <span class="ruby-comment"># =&gt; {:foo=&gt;&quot;bar&quot;}</span>
</pre>

<p>Raises a TypeError when ‘yaml` parameter is NilClass</p>

<p>NOTE: This method *should not* be used to parse untrusted documents, such as YAML documents that are supplied via user input.  Instead, please use the load method or the <a href="Psych.html#method-c-safe_load"><code>safe_load</code></a> method.</p>

                              <div class="method-source-code" id="unsafe_load-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 271</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">unsafe_load</span> <span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">fallback:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">symbolize_names:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">freeze:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">strict_integer:</span> <span class="ruby-keyword">false</span>
  <span class="ruby-identifier">result</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">yaml</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">fallback</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">result</span>
  <span class="ruby-identifier">result</span>.<span class="ruby-identifier">to_ruby</span>(<span class="ruby-value">symbolize_names:</span> <span class="ruby-identifier">symbolize_names</span>, <span class="ruby-value">freeze:</span> <span class="ruby-identifier">freeze</span>, <span class="ruby-value">strict_integer:</span> <span class="ruby-identifier">strict_integer</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-unsafe_load_file" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">unsafe_load_file</span><span
                                class="method-args">(filename, **kwargs)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Load the document contained in <code>filename</code>.  Returns the yaml contained in <code>filename</code> as a Ruby object, or if the file is empty, it returns the specified <code>fallback</code> return value, which defaults to <code>false</code>.</p>

<p>NOTE: This method *should not* be used to parse untrusted documents, such as YAML documents that are supplied via user input.  Instead, please use the <a href="Psych.html#method-c-safe_load_file"><code>safe_load_file</code></a> method.</p>

                              <div class="method-source-code" id="unsafe_load_file-source">
            <pre><span class="ruby-comment"># File psych/lib/psych.rb, line 647</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">unsafe_load_file</span> <span class="ruby-identifier">filename</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>
  <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-string">&#39;r:bom|utf-8&#39;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">unsafe_load</span> <span class="ruby-identifier">f</span>, <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

